﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Cabinet.Master" Inherits="System.Web.Mvc.ViewPage<nsadv.Statistic.Web.ViewModels.CabinetModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CabinetTitleContent" runat="server">
    Статистика
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CabinetContent" runat="server">
    <div class="sortbox">

        Платформа
        <select class="sort updatedetails" id="PlatformId">
            <% if (Model.ShowAllPlatforms)
      {%>
            <option value="">Все</option>
            <%
                }%>
            <% foreach (var platform in Model.Platforms)
      {%>
            <option value="<%: platform.Id %>">
                <%: platform.Name %></option>
            <%
                }%>
        </select>

		<% if (Model.ShowPlaces) 
		{%>
			Площадка
			<select class="sort updatedetails" id="PlaceId">
				<% if (Model.ShowAllPlaces)
		  {%>
				<option value="">Все</option>
				<%
					}%>
				<% foreach (var place in Model.Places)
		  {%>
				<option value="<%: place.Id %>">
					<%: place.Name %></option>
				<%
					}%>
			</select>
		<%} %>

        Рекламная кампания
        <select class="sort updatedetails" id="CampaignId">
            <% if (Model.ShowAllCampaigns)
      {%>
            <option value="">Все</option>
            <%
                }%>
            <% foreach (var campaign in Model.Campaigns)
      {%>
            <option value="<%: campaign.Id %>">
                <%: campaign.Name%></option>
            <%
                }%>
        </select>

    </div>
    <div id="statisticdetails">
    </div>
    <script type="text/javascript">
        function handleFailure(ajaxContext) {
            $("#statisticdetails").html('<div class="stat-loader-text">Ошибка...</div><p>' + ajaxContext.get_data() +'</p>');
        }

        function handleSuccess(ajaxContext) {
            $('.tooltip').tooltip({bgcolor: '#ede5b8', bordercolor: '#bf9552', fontcolor: '#000000'});		
        }

        function UpdateDetails() {
        	$("#statisticdetails").html('<div class="stat-loader-text">Загрузка статистики <span id="stat-loader-text-times"></span>...</div><img class="stat-loader" src="/Content/img/ajax-loader.gif" alt="loader" />');

            Sys.Mvc.MvcHelpers._asyncRequest(
            '<%: Url.Action("Details", "Statistic", null) %>',
            'post',
               'PlatformId=' + $("#PlatformId")[0].value
			+ '&CampaignId=' + $("#CampaignId")[0].value
			<% if (Model.ShowPlaces) { %>
			+ '&PlaceId=' + $("#PlaceId")[0].value
			<%} %>
			+ '&Archive=<%: Model.Archive %>',
            '',
            { insertionMode: Sys.Mvc.InsertionMode.replace,
              updateTargetId: 'statisticdetails',
              onSuccess: Function.createDelegate(this, handleSuccess), 
              onFailure: Function.createDelegate(this, handleFailure),
              LoadingElementId: 'stat-loader-text-times'
             });
        }
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="DocumentReadyScript" runat="server">
    $(".updatedetails").change( function(){ UpdateDetails(); });
    UpdateDetails();
</asp:Content>
